package com.filemanager;

import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
anya trying to serialize here
 */
public class Person {

        private String firstName;
        private String lastName;

        public String getFirstName() {
            return firstName;
        }

        public String getLastName() {
            return lastName;
        }

        public void setFirstName(String str) {
            firstName = str;
        }

        public void setLastName(String str) {
            lastName = str;
        }



    public static void main(String[] args) {


        FileOutputStream os = null;
        try {
            os = new FileOutputStream("ololo.xml");
        } catch (FileNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        XMLEncoder encoder = new XMLEncoder(os);
        Person p = new Person();
        p.setFirstName("Anya");
        encoder.writeObject(p);
        encoder.close();

//        decoding
        FileInputStream is = null;
        try {
            is = new FileInputStream("ololo.xml");
        } catch (FileNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        XMLDecoder decoder = new XMLDecoder(is);
        Person p2 = (Person) decoder.readObject();
        System.out.println(p2.toString());
        decoder.close();

    }
}
